<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Support\Facades\DB;
use App\Models\OperatorLog as OperatorLogModel;
class OperatorLog
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $data['ip'] = $request->getClientIp();
        $data['method'] = $request->method();
        $data['user_id'] = auth('admin')->user()->id;
        $data['path'] = $request->path();
        $data['input'] = json_encode($request->except('_token'));
        OperatorLogModel::query()->create($data);
        return $next($request);
    }
}
